package cn.xaut.XAUT迎春杯预热;

import static java.lang.Math.*;
import java.util.Scanner;

/**
 * F - 最短区间
 * 考点：滑动窗口
 */
public class demoF_3 {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);
        int s = input.nextInt();
        int n = input.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = input.nextInt();

        int res = Integer.MAX_VALUE;
        int start = 0, end = 0, sum = 0;
        while (end < n) {
            sum += a[end];
            while (sum >= s) {
                res = min(res, end - start + 1);
                sum -= a[start];
                start ++;
            }
            end ++;
        }
        System.out.println(res == Integer.MAX_VALUE ? 0 : res);
    }
}
